<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        window.onload= function () {
            var btn1=document.querySelector("#btn1");
            var btn2=document.querySelector("#btn2");
            var timerId=null;//储存间歇定时器的id值
            btn1.onclick=function(){
                timerId=setInterval(function(){
                    console.log("一闪一闪。亮晶晶。");
                },1000)
            }
            btn2.onclick=function(){
                clearInterval(timerId);
            }
        }
    </script>
</head>
<body>
<button id="btn1">设置闹钟</button>
<button id="btn2">取消闹钟</button>

</body>
</html>